/* eslint-disable no-case-declarations */

// import qs from "qs";
import { onMounted, ref } from "vue";
import WOW from "wow.js";
import { useRouter } from "vue-router";
import { getStudentModuleInfos } from "@/api/routes";
import { ElMessage } from "element-plus";
import qs from "qs";

export function useExample() {
  const router = useRouter();

  async function jump(row: any) {
    const data = qs.stringify({
      moduleId: row
    });
    let res = await getStudentModuleInfos(data);
    if (res.success) {
      const jumps = typeof row == "string";
      sessionStorage.setItem("moduleId", JSON.stringify(row));
      if (jumps) {
        router.push({
          path: "/student/data_scene/tasklist"
        });
        return;
      }
      switch (row) {
        case 2:
          // 监控中心
          router.push("/student/data_scene/monitoring_center");
          break;
        case 7:
          // TODO:智能测评
          router.push({
            path: "/student/Intelligent_evaluation"
          });
          break;
      }
    } else {
      ElMessage.warning(res.msg);
    }
  }

  onMounted(async () => {
    // sessionStorage.setItem("routeState", JSON.stringify(false));
    const wow = new WOW({
      boxClass: "wow", // animated element css class (default is wow)
      animateClass: "animated", // animation css class (default is animated)
      offset: 0, // distance to the element when triggering the animation (default is 0)
      mobile: true, // trigger animations on mobile devices (default is true)
      live: true, // act on asynchronously loaded content (default is true)
      scrollContainer: null, // optional scroll container selector, otherwise use window,
      resetAnimation: true // reset animation on end (default is true)
    });
    wow.init();
  });

  return { jump };
}
